<template>
<!-- 上传投保单 表单页 -->
    <el-form label-width="120px">       
        <el-form-item label="附件上传">
            <el-button type="primary" class="fileselect">
                <input type="file" @change="upload" value="" id="fileup"> 上传附件
            </el-button>
        </el-form-item>
        <el-form-item style="text-align:center">
            <el-button type="primary" @click="onSubmit">提交</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
import { mapState } from "vuex";
import api from "@/js/api";
export default {
  data() {
    return {
      //   formInline: {
      //     user: "",
      //     region: ""
      //   }
    };
  },
  props: {
    id: {
      type: String,
      default: ""
    }
  },
  computed: mapState({
    saleDetail: state => state.SealDetail.model
  }),
  methods: {
    onSubmit() {
      if (!this.saleDetail.SALESDETAIL_DOC) {
        that.$notify.error({
          title: "失败",
          message: "您还没有上传附件"
        });
        return;
      }
      this.saleDetail.SALESDETAIL_ID = this.id;
      this.saleDetail.SALESDETAIL_CHECKSTATE = "投保单审核";
      api.SaledetailUpdatePart(this, this.saleDetail);
    },
    upload() {
      let file = event.target.files[0];
      if (file) {
        const formData = new FormData();
        formData.append("file", file);
        let that = this;
        api.uploadFile(this, formData, function(msg) {
          document.getElementById("fileup").value = "";
          that.saleDetail.SALESDETAIL_DOC = msg.Result.FilesList[0];
          // console.log(that.saleDetail);
        });
      }
    }
  },
  created() {
    this.$store.commit("changer", {});
  }
};
</script>

<style>

</style>
